home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ANSIVIEW.ZIP / ANSIVIEW.PAS < prev    next >
Pascal/Delphi Source File  |  1991-01-30  |  22KB  |  743 lines

  1. Unit AnsiView;
  2.  
  3. {     ANSIVIEW.PAS - 24 January 1991
  4.  
  5.                           By Marcos R. Della
  6.                              5084 Rincon Ave.
  7.                              Santa Rosa, CA 95409
  8.  
  9.                              CIS: 71675,765
  10.  
  11.       This Unit was written so that I had something that reminded me of the
  12.       original WRITELN and WRITE statments of pascal where I was working
  13.       with the screen and there were various definate controls I had using
  14.       the GOTOXY and CLRSCR routines.  Under TVision, you no longer have
  15.       these controls and need to learn a completely different way of getting
  16.       info on the screen.
  17.  
  18.       AnsiView was written to give you some of these old methods while still
  19.       using the TVision platform. That is, your screen is a scroll window of
  20.       your size choosing (You can define a screen 128,2048 and use the gotoxy
  21.       to get to anywhere on that screen!)  Also if you turn on the ANSI
  22.       option, the driver will recognise ANSI controls (For reading those ANSI
  23.       files directly and displaying them!)
  24.  
  25.       Because this is also a TVision enviroment, your screen will also be
  26.       saved if you do a desktop save! Wonderful stuff eh?
  27.  
  28.  
  29.       NOTE!!!   Registration values used by this Unit
  30.  
  31.                     TANSIView = 7200;
  32.                     TInterior = 7201;
  33.  
  34.       --------------------
  35.       Modification History
  36.       --------------------
  37.  
  38.       29 January 1991 - Added the code to handle 15 of the ANSI control
  39.                         characters if they are passed to the ANSIView
  40.       routines.  There are two commands that will no work with this current
  41.       implementation. The <ESC>[xP and <ESC>[x@ for insert and delete
  42.       characters on the current line.  These should be supported in the
  43.       near future whenever I get back to working on this unit...
  44.  
  45.       There is a problem with the cursor positioning not always updating
  46.       the onscreen cursor display (if you have it on) however with the
  47.       printing of any character or other command, it comes back on. I'm
  48.       still scratching my head over this one.
  49.  
  50.       30 January 1991 - I know, I'm making too many changes... Oh well...
  51.                         Anyway, the code has been added for the insert and
  52.       delete characters on the line.  Turned out to be easier than I thought.
  53.       Also some redundant .DrawViews were removed to help speed up the
  54.       execution.  If only I could figure out Turbo Profiler...
  55.       NOTE:  There are a few ANSI sequences that are related to the keyboard
  56.       handler and cursor request.  These are coded into the system so that
  57.       they do not produce display errors, however the code does nothing other
  58.       than strip out the sequences from the display.
  59.  
  60. }
  61.  
  62. {$DEFINE ANSICOMPAT} { Define this if you want the code compiled that will
  63.                        allow you to have ANSI compatability. If you have no
  64.                        use for the ANSI routines, feel free to undefine this
  65.                        and save a little code space... (Around 2.2k) }
  66.  
  67. {$F+,O+,R-,S-}
  68.  
  69. Interface
  70.  
  71. Uses Dos, Drivers, Views, Objects, Memory;
  72.  
  73. CONST MaxViewHeight = 2048;
  74.       MaxParms      = 5;     {If you can't do it in 5 ANSI parms...}
  75.  
  76. TYPE  PScreenL  = ^TScreenL;
  77.       TScreenL  = ARRAY[0..MaxViewWidth - 1] OF WORD;
  78.  
  79.       PScreenR  = ^TScreenR;
  80.       TScreenR  = ARRAY[0..MaxViewHeight - 1] OF PScreenL;
  81.  
  82.       PInterior = ^TInterior;
  83.       TInterior = OBJECT(TScroller)
  84.                      AutoScroll : BOOLEAN;
  85.                      MaxDim     : TPoint;
  86.                      CurLoc     : TPoint;
  87.                      TopPtr     : PScreenR;
  88.                      CONSTRUCTOR Init(VAR Bounds : TRect; Limits : TPoint;
  89.                                           Color : BYTE; AHScrollBar, AVScrollBar : PScrollBar);
  90.                      CONSTRUCTOR Load(VAR S : TStream);
  91.                      PROCEDURE Store(VAR S : TStream);
  92.                      PROCEDURE Draw; VIRTUAL;
  93.                      PROCEDURE PrintChar(Ch : CHAR; VAR TextAttr : BYTE);
  94.                      DESTRUCTOR Done; VIRTUAL;
  95.                   END;
  96.  
  97.       ParmsFld  = ARRAY[1..MaxParms] OF BYTE;
  98.  
  99.       PANSIView = ^TANSIView;
  100.       TANSIView = OBJECT(TWindow)
  101.                      UseANSI    : BOOLEAN;
  102.                      CurHold    : TPoint;
  103.                      EndString  : CHAR;
  104.                      ESCBuf     : STRING[MaxParms * 3 + 4];
  105.                                                {Max needed since we do not
  106.                                                 support string redifinition}
  107.                      ParmsIdx   : BYTE;
  108.                      StateInfo  : BYTE;
  109.                      ANSIParms  : ParmsFld;
  110.                      TextAttr   : BYTE;
  111.                      Interior   : PInterior;
  112.                      CONSTRUCTOR Init(Bounds : TRect; Limits : TPoint; WnTitle : STRING; WindowNo : WORD);
  113.                      CONSTRUCTOR Load(VAR S : TStream);
  114.                      PROCEDURE Store(VAR S : TStream);
  115.                      FUNCTION  ProcessChar(Ch : CHAR) : BOOLEAN;
  116.  
  117.                      PROCEDURE PrintLN(s : STRING);
  118.                      PROCEDURE Print(s : STRING);
  119.                      PROCEDURE PrintChar(Ch : CHAR);
  120.                      PROCEDURE PutChar(X, Y : WORD; Ch : CHAR; Attr : BYTE);
  121.  
  122.                      PROCEDURE CursorOn;
  123.                      PROCEDURE CursorOff;
  124.                      PROCEDURE AutoScrollOn;
  125.                      PROCEDURE AutoScrollOff;
  126.  
  127.                      PROCEDURE ClrScr;
  128.                      PROCEDURE ClrEol;
  129.                      PROCEDURE DelLine;
  130.                      PROCEDURE GotoXY(X,Y : WORD);
  131.                      PROCEDURE HighVideo;
  132.                      PROCEDURE InsLine;
  133.                      PROCEDURE LowVideo;
  134.                      PROCEDURE TextBackground(Color : BYTE);
  135.                      PROCEDURE TextColor(Color : BYTE);
  136.                      FUNCTION WhereX : BYTE;
  137.                      FUNCTION WhereY : WORD;
  138.                   END;
  139.  
  140. CONST RANSIView: TStreamRec = (
  141.          ObjType: 7200;
  142.          VmtLink: Ofs(TypeOf(TANSIView)^);
  143.          Load:    @TANSIView.Load;
  144.          Store:   @TANSIView.Store
  145.       );
  146.  
  147.       RInterior: TStreamRec = (
  148.          ObjType: 7201;
  149.          VmtLink: Ofs(TypeOf(TInterior)^);
  150.          Load:    @TInterior.Load;
  151.          Store:   @TInterior.Store
  152.       );
  153.  
  154. PROCEDURE RegisterANSIView;
  155.  
  156. Implementation
  157.  
  158. {----------------------------------------------------------------------------}
  159.  
  160. FUNCTION Min(X,Y : INTEGER) : INTEGER; ASSEMBLER;
  161. ASM
  162.    MOV   AX,X
  163.    CMP   AX,Y
  164.    JLE   @@1
  165.    MOV   AX,Y
  166. @@1:
  167. END;
  168.  
  169. FUNCTION Max(X,Y : INTEGER) : INTEGER; ASSEMBLER;
  170. ASM
  171.    MOV   AX,X
  172.    CMP   AX,Y
  173.    JGE   @@1
  174.    MOV   AX,Y
  175. @@1:
  176. END;
  177.  
  178. {----------------------------------------------------------------------------}
  179.  
  180. CONSTRUCTOR TInterior.Init;
  181. VAR   i,j : WORD;
  182. BEGIN
  183.    TScroller.Init(Bounds,AHScrollBar,AVScrollBar);
  184.    MaxDim     := Limits;
  185.    AutoScroll := TRUE;
  186.    CurLoc.X   := 0;
  187.    CurLoc.Y   := 0;
  188.    TopPtr := MemAlloc(MaxDim.Y * SIZEOF(PScreenR));     {Allocate All Y Coords}
  189.    IF TopPtr = NIL THEN
  190.       BEGIN
  191.          TScroller.Done;
  192.          FAIL
  193.       END;
  194.    FOR i := 0 TO MaxDim.Y - 1 DO BEGIN                  {Now for each line}
  195.       TopPtr^[i] := MemAlloc(MaxDim.X * SIZEOF(WORD));
  196.       IF TopPtr^[i] = NIL THEN
  197.          BEGIN
  198.             IF i > 0 THEN
  199.                FOR j := 0 TO i - 1 DO
  200.                   FREEMEM(TopPtr^[j],MaxDim.X * SIZEOF(WORD));
  201.             FREEMEM(TopPtr,MaxDim.Y * SIZEOF(PScreenR));
  202.             TScroller.Done;
  203.             FAIL
  204.          END
  205.       ELSE
  206.          MoveChar(TopPtr^[i]^,' ',Color,MaxDim.X)
  207.    END;
  208.    GrowMode := gfGrowHiX + gfGrowHiY;
  209.    DragMode := dmLimitLoX + dmLimitLoY;
  210.    SetLimit(MaxDim.X,MaxDim.Y);
  211. END;
  212.  
  213. CONSTRUCTOR TInterior.Load;
  214. VAR   i,j : INTEGER;
  215.       ok  : BOOLEAN;
  216.       B   : TDrawBuffer;
  217. BEGIN
  218.    TScroller.Load(S);
  219.    S.Read(AutoScroll,SIZEOF(AutoScroll));
  220.    S.Read(CurLoc,SIZEOF(CurLoc));
  221.    S.Read(MaxDim,SIZEOF(MaxDim));
  222.    TopPtr := MemAlloc(MaxDim.Y * SIZEOF(PScreenR));
  223.    ok := (TopPtr <> NIL);
  224.    FOR i := 0 TO MaxDim.Y - 1 DO BEGIN
  225.       S.Read(B,MaxDim.X * SIZEOF(WORD));
  226.       IF ok THEN
  227.          BEGIN
  228.             TopPtr^[i] := MemAlloc(MaxDim.X * SIZEOF(WORD));
  229.             ok := ok AND (TopPtr^[i] <> NIL);
  230.             IF ok THEN
  231.                MOVE(B,TopPtr^[i]^,MaxDim.X * SIZEOF(WORD))
  232.             ELSE
  233.                IF i > 0 THEN
  234.                   FOR j := 0 TO i - 1 DO
  235.                      FREEMEM(TopPtr^[j],MaxDim.X * SIZEOF(WORD));
  236.          END
  237.    END;
  238.    IF NOT ok THEN
  239.       BEGIN
  240.          FREEMEM(TopPtr,MaxDim.Y * SIZEOF(PScreenR));
  241.          TScroller.Done;
  242.          FAIL
  243.       END
  244. END;
  245.  
  246. PROCEDURE TInterior.Store;
  247. VAR   i : INTEGER;
  248. BEGIN
  249.    TScroller.Store(S);
  250.    S.Write(AutoScroll,SIZEOF(AutoScroll));
  251.    S.Write(CurLoc,SIZEOF(CurLoc));
  252.    S.Write(MaxDim,SIZEOF(MaxDim));
  253.    FOR i := 0 TO MaxDim.Y - 1 DO
  254.       S.Write(TopPtr^[i]^,MaxDim.X * SIZEOF(WORD));
  255. END;
  256.  
  257. PROCEDURE TInterior.Draw;
  258. VAR   Y : INTEGER;
  259. BEGIN
  260.    FOR Y := 0 TO Size.Y - 1 DO
  261.       WriteLine(0,Y,Size.X,1,TopPtr^[Delta.Y + Y]^[Delta.X])
  262. END;
  263.  
  264. PROCEDURE TInterior.PrintChar;
  265. VAR   PPtr : PScreenL;
  266.       Y    : INTEGER;
  267. BEGIN
  268.    CASE ch OF
  269.       #7  : BEGIN
  270.                SOUND(1000);
  271.                DELAY(100);
  272.                NOSOUND
  273.             END;
  274.       #8  : DEC(CurLoc.X);
  275.       #10 : INC(CurLoc.Y);
  276.       #13 : CurLoc.X := 0;
  277.       ELSE  BEGIN
  278.                MoveChar(TopPtr^[CurLoc.Y]^[CurLoc.X],ch,TextAttr,1);
  279.                INC(CurLoc.X)
  280.             END;
  281.    END;
  282.  
  283.    {Next insure that the X position didn't go out of bounds.}
  284.    {If it did, then set it back in bounds and scroll if needed.}
  285.  
  286.    CurLoc.X := Max(CurLoc.X,0);
  287.    IF CurLoc.X >= MaxDim.X THEN
  288.       BEGIN
  289.          INC(CurLoc.Y);
  290.          CurLoc.X := 0
  291.       END;
  292.  
  293.    {Finally check to see if we went beyond the Y Coordinate and need to}
  294.    {scroll the screen up a line for the next line to be put on.}
  295.  
  296.    IF CurLoc.Y >= MaxDim.Y THEN
  297.       BEGIN
  298.          DEC(CurLoc.Y);
  299.          PPtr := TopPtr^[0];
  300.  
  301.          MoveChar(PPtr^,' ',TextAttr,MaxDim.X);
  302.          MOVE(TopPtr^[1],TopPtr^[0],(MaxDim.Y - 1) * SIZEOF(PScreenL));
  303.          TopPtr^[MaxDim.Y - 1] := PPtr
  304.       END;
  305.  
  306.    IF AutoScroll AND (Size.Y <= CurLoc.Y - Delta.Y) THEN
  307.       VScrollBar^.SetValue(Max(CurLoc.Y - Size.Y + 1,0))
  308. END;
  309.  
  310.  
  311. DESTRUCTOR TInterior.Done;
  312. VAR   i : WORD;
  313. BEGIN
  314.    FOR i := 0 TO MaxDim.Y - 1 DO
  315.       FREEMEM(TopPtr^[i],MaxDim.X * SIZEOF(WORD));
  316.    FREEMEM(TopPtr,MaxDim.Y * SIZEOF(PScreenR));
  317.    TScroller.Done
  318. END;
  319.  
  320. {----------------------------------------------------------------------------}
  321.  
  322. CONSTRUCTOR TANSIView.Init;
  323. VAR   HScrollBar,
  324.       VScrollBar : PScrollBar;
  325. BEGIN
  326.    TWindow.Init(Bounds,WnTitle,WindowNo);
  327.  
  328.    TextAttr := $1E;
  329.  
  330.    GetExtent(Bounds);
  331.    Bounds.Grow(-1,-1);
  332.  
  333.    Limits.X := Max(Limits.X,MinWinSize.X);
  334.    Limits.X := Min(Limits.X,MaxViewHeight);
  335.    Limits.X := Max(Limits.X,Bounds.B.X - Bounds.A.X);
  336.  
  337.    Limits.Y := Max(Limits.Y,MinWinSize.Y);
  338.    Limits.Y := Min(Limits.Y,MaxViewWidth);
  339.    Limits.Y := Max(Limits.Y,Bounds.B.Y - Bounds.A.Y);
  340.  
  341.    VScrollBar := StandardScrollBar(sbVertical);
  342.    HScrollBar := StandardScrollBar(sbHorizontal);
  343.    Interior := NEW(PInterior,Init(Bounds,Limits,TextAttr,HScrollBar,VScrollBar));
  344.    IF Interior = NIL THEN
  345.       BEGIN
  346.          TWindow.Done;
  347.          FAIL
  348.       END;
  349.    StateInfo := 0;
  350.    UseANSI := TRUE;
  351.    CurHold.X := 0;
  352.    CurHold.Y := 0;
  353.    Insert(Interior)
  354. END;
  355.  
  356. CONSTRUCTOR TANSIView.Load;
  357. BEGIN
  358.    TWindow.Load(S);
  359.    GetPeerViewPtr(S,Interior);
  360.    S.Read(TextAttr,SIZEOF(TextAttr));
  361.    S.Read(UseANSI,SIZEOF(UseANSI));
  362.    S.Read(CurHold,SIZEOF(CurHold));
  363.    StateInfo := 0
  364. END;
  365.  
  366. PROCEDURE TANSIView.Store;
  367. BEGIN
  368.    TWindow.Store(S);
  369.    PutPeerViewPtr(S,Interior);
  370.    S.Write(TextAttr,SIZEOF(TextAttr));
  371.    S.Write(UseANSI,SIZEOF(UseANSI));
  372.    S.Write(CurHold,SIZEOF(CurHold));
  373. END;
  374.  
  375. FUNCTION TANSIView.ProcessChar(Ch : CHAR) : BOOLEAN;
  376.  
  377. {$IFDEF ANSICOMPAT}
  378.    PROCEDURE ChangeTextAttr(VAR TAttr : BYTE; PNum : BYTE; PFld : ParmsFld);
  379.    CONST Colors = 22;
  380.          ColorTbl : ARRAY[1..Colors,1..3] OF BYTE =
  381.                     ((0,  $00, $07),   (5,  $FF, $80),
  382.                      (1,  $FF, $08),   (7,  $F8, $70),
  383.                      (4,  $F8, $01),   (8,  $88, $00),
  384.  
  385.                      (30, $F8, $00),   (40, $8F, $00),
  386.                      (31, $F8, $04),   (41, $8F, $40),
  387.                      (32, $F8, $02),   (42, $8F, $20),
  388.                      (33, $F8, $06),   (43, $8F, $60),
  389.                      (34, $F8, $01),   (44, $8F, $10),
  390.                      (35, $F8, $05),   (45, $8F, $50),
  391.                      (36, $F8, $03),   (46, $8F, $30),
  392.                      (37, $F8, $07),   (47, $8F, $70));
  393.    BEGIN
  394.  
  395.       ASM
  396.       mov     si,OFFSET ANSIParms
  397.       xor     cx,cx
  398.       mov     cl,PNum
  399.  
  400.       or      cx,cx
  401.       jnz     @sgr_loop
  402.       mov     [si],cl
  403.       inc     cx
  404.  
  405.    @sgr_loop:
  406.       lodsb
  407.       push    cx
  408.       mov     cx,Colors
  409.       mov     bx,OFFSET ColorTbl - 3
  410.  
  411.    @sgr_search:
  412.       add     bx,3
  413.       cmp     al,[bx]
  414.       loopne  @sgr_search
  415.       jne     @sgr_loopx
  416.  
  417.       mov     cx,1[bx]
  418.       les     bx,TAttr
  419.       mov     al,es:[bx]
  420.       and     al,cl
  421.       or      al,ch
  422.       mov     es:[bx],al
  423.  
  424.    @sgr_loopx:
  425.       pop     cx
  426.       loop    @sgr_loop
  427.       END
  428.  
  429.    END;
  430. {$ENDIF}
  431.  
  432.    PROCEDURE ProcessCommand(Ch : CHAR);
  433. {$IFDEF ANSICOMPAT}
  434.    VAR   loop      : INTEGER;
  435.          CurL      : TPoint;
  436.          CharSlide : WORD;
  437. {$ENDIF}
  438.    BEGIN
  439. {ED}  IF (Ch = 'J') AND (ANSIParms[1] = 2) THEN   { Special Case...   }
  440.          BEGIN                                    { Handle regardless }
  441.             ClrScr;                               { of UseANSI status }
  442.             EXIT
  443.          END;
  444.  
  445. {$IFDEF ANSICOMPAT}
  446.       WITH Interior^ DO BEGIN
  447.          IF NOT UseANSI THEN
  448.             EXIT;
  449.          CurL.X := CurLoc.X + 1;
  450.          CurL.Y := CurLoc.Y + 1;
  451.          CASE Ch OF
  452. {ICH}       '@' : BEGIN
  453.                      CharSlide := Min(ANSIParms[1],MaxDim.X - CurLoc.X);
  454.                      MOVE(TopPtr^[CurLoc.Y]^[CurLoc.X],
  455.                           TopPtr^[CurLoc.Y]^[CurLoc.X + CharSlide],
  456.                           (MaxDim.X - CurLoc.X - CharSlide) * SIZEOF(WORD));
  457.                      MoveChar(TopPtr^[CurLoc.Y]^[CurLoc.X],' ',TextAttr,CharSlide);
  458.                      Interior^.DrawView
  459.                   END;
  460. {CUU}       'A' : GotoXY(CurL.X,Max(0,CurL.Y - ANSIParms[1]));
  461. {CUD}       'B' : GotoXY(CurL.X,Min(MaxDim.Y,CurL.Y + ANSIParms[1]));
  462. {CUF}       'C' : GotoXY(Min(CurL.X + ANSIParms[1],MaxDim.X),CurL.Y);
  463. {CUB}       'D' : GotoXY(Max(CurL.X - ANSIParms[1],0) + 1,CurL.Y);
  464. {CUP,HVP}   'H',
  465.             'f' : GotoXY(Min(MaxDim.X,ANSIParms[2]),Min(MaxDim.Y,ANSIParms[1]));
  466. {EL}        'K' : ClrEol;
  467. {IL}        'L' : FOR Loop := 1 TO ANSIParms[1] DO
  468.                      InsLine;
  469. {DL}        'M' : FOR Loop := 1 TO ANSIParms[1] DO
  470.                      DelLine;
  471. {DCH}       'P' : BEGIN
  472.                      CharSlide := Min(ANSIParms[1],MaxDim.X - CurLoc.X);
  473.                      MOVE(TopPtr^[CurLoc.Y]^[CurLoc.X + CharSlide],
  474.                           TopPtr^[CurLoc.Y]^[CurLoc.X],
  475.                           (MaxDim.X - CurLoc.X - CharSlide) * SIZEOF(WORD));
  476.                      MoveChar(TopPtr^[CurLoc.Y]^[MaxDim.X - CharSlide],' ',TextAttr,CharSlide);
  477.                      Interior^.DrawView
  478.                   END;
  479. {SM}        'h' : ;
  480. {RM}        'l' : ;
  481. {SGR}       'm' : ChangeTextAttr(TextAttr,ParmsIdx,ANSIParms);
  482. {DSR}       'n' : IF ANSIParms[1] <> 6 THEN
  483.                      EXIT;
  484. {IBMKKR}    'p' : ;
  485. {SCP}       's' : CurHold := CurL;
  486. {RCP}       'u' : GotoXY(CurHold.X,CurHold.Y);
  487. {DKOCT}     'y' : ;
  488.             ELSE  EXIT
  489.          END
  490.       END;
  491.       ESCBuf := ''
  492. {$ENDIF}
  493.    END;
  494.  
  495. LABEL ReEval;
  496. VAR   i : INTEGER;
  497.  
  498. BEGIN
  499.    ProcessChar := TRUE;
  500.    IF (Ch <> #27) AND (StateInfo = 0) THEN
  501.       Interior^.PrintChar(Ch,TextAttr)
  502.    ELSE
  503.       BEGIN
  504.          ProcessChar := FALSE;
  505.          ESCBuf := ESCBuf + Ch;
  506.  
  507. ReEval:
  508.          CASE StateInfo OF
  509.  
  510.             0 : BEGIN
  511.                    StateInfo := 1;
  512.                    ESCBuf := #27
  513.                 END;
  514.  
  515. {f_bracket}
  516.             1 : StateInfo := ORD(Ch = '[') SHL 1;
  517.  
  518. {f_get_args}
  519.             2 : BEGIN
  520.                    StateInfo := 3;
  521.                    ParmsIdx := 0;
  522.                    FILLCHAR(ANSIParms,SIZEOF(ANSIParms),1);
  523.                    IF (Ch <> '=') AND (Ch <> '?') THEN
  524.                       GOTO ReEval
  525.                 END;
  526.  
  527. {f_get_param}
  528.             3 : IF (Ch >= '0') AND (Ch <= '9') THEN
  529.                    BEGIN
  530.                       INC(ParmsIdx);
  531.                       ParmsIdx := Min(ParmsIdx,SIZEOF(ANSIParms));
  532.                       ANSIParms[ParmsIdx] := ORD(Ch) - $30;
  533.                       StateInfo := 6
  534.                    END
  535.                 ELSE
  536.                    IF (Ch = '''') OR (Ch = '"') THEN
  537.                       BEGIN
  538.                          StateInfo := 4;
  539.                          EndString := Ch
  540.                       END
  541.                    ELSE
  542.                       BEGIN
  543.                          StateInfo := 7;
  544.                          GOTO ReEval
  545.                       END;
  546.  
  547. {f_get_string}
  548.             4 : INC(StateInfo,ORD(Ch = EndString));
  549.  
  550. {f_eat_semi}
  551.             5 : StateInfo := ORD(Ch = ';') * 3;
  552.  
  553. {f_in_param}
  554.             6 : IF (Ch >= '0') AND (Ch <= '9') THEN
  555.                    ANSIParms[ParmsIdx] := ANSIParms[ParmsIdx] * 10
  556.                                         + ORD(Ch) - $30
  557.                 ELSE
  558.                    BEGIN
  559.                       StateInfo := 7;
  560.                       GOTO ReEval
  561.                    END;
  562.  
  563. {fgp_semi_or_cmd}
  564.             7 : BEGIN
  565.                    StateInfo := ORD(Ch = ';') * 3;
  566.                    IF StateInfo = 0 THEN
  567.                       ProcessCommand(Ch)
  568.                 END
  569.          END;
  570.  
  571.          IF (StateInfo = 0) AND (LENGTH(ESCBuf) > 0) OR
  572.             (LENGTH(ESCBuf) = SIZEOF(ESCBuf) - 1) THEN
  573.             BEGIN
  574.                FOR i := 1 TO LENGTH(ESCBuf) DO
  575.                   Interior^.PrintChar(ESCBuf[1],TextAttr);
  576.                StateInfo := 0;
  577.                ProcessChar := TRUE
  578.             END
  579.       END
  580. END;
  581.  
  582. PROCEDURE TANSIView.PrintLN;
  583. BEGIN
  584.    Print(s + #13 + #10)
  585. END;
  586.  
  587. PROCEDURE TANSIView.Print;
  588. VAR   Loop      : INTEGER;
  589.       ValidDisp : BOOLEAN;
  590. BEGIN
  591.    IF LENGTH(s) > 0 THEN
  592.       BEGIN
  593.          ValidDisp := FALSE;
  594.          FOR Loop := 1 TO LENGTH(s) DO
  595.             ValidDisp := ProcessChar(s[Loop]) OR ValidDisp;
  596.          IF ValidDisp THEN
  597.             BEGIN
  598.                SetCursor(Interior^.CurLoc.X,Interior^.CurLoc.Y);
  599.                Interior^.DrawView
  600.             END
  601.       END
  602. END;
  603.  
  604. PROCEDURE TANSIView.PrintChar;
  605. BEGIN
  606.    IF ProcessChar(Ch) THEN
  607.       BEGIN
  608.          SetCursor(Interior^.CurLoc.X,Interior^.CurLoc.Y);
  609.          Interior^.DrawView
  610.       END
  611. END;
  612.  
  613. PROCEDURE TANSIView.PutChar;
  614. BEGIN
  615.    IF (X >= 0) AND (X < Interior^.MaxDim.X) AND
  616.       (Y >= 0) AND (Y < Interior^.MaxDim.Y) THEN
  617.       BEGIN
  618.          IF ch <> #0 THEN
  619.             WordRec(Interior^.TopPtr^[Y]^[X]).LO := ORD(Ch);
  620.          IF Attr <> 0 THEN
  621.             WordRec(Interior^.TopPtr^[Y]^[X]).HI := Attr;
  622.          Interior^.DrawView
  623.       END
  624. END;
  625.  
  626. PROCEDURE TANSIView.CursorOn;
  627. BEGIN
  628.    Interior^.ShowCursor
  629. END;
  630.  
  631. PROCEDURE TANSIView.CursorOff;
  632. BEGIN
  633.    Interior^.HideCursor
  634. END;
  635.  
  636. PROCEDURE TANSIView.AutoScrollOn;
  637. BEGIN
  638.    Interior^.AutoScroll := TRUE
  639. END;
  640.  
  641. PROCEDURE TANSIView.AutoScrollOff;
  642. BEGIN
  643.    Interior^.AutoScroll := FALSE
  644. END;
  645.  
  646. PROCEDURE TANSIView.ClrScr;
  647. VAR   i : INTEGER;
  648. BEGIN
  649.    SetCursor(0,0);
  650.    Interior^.CurLoc.X := 0;
  651.    Interior^.CurLoc.Y := 0;
  652.    FOR i := 0 TO Interior^.MaxDim.Y - 1 DO
  653.       MoveChar(Interior^.TopPtr^[i]^,' ',TextAttr,Interior^.MaxDim.X);
  654.    Interior^.VScrollBar^.SetValue(0);
  655.    Interior^.HScrollBar^.SetValue(0);
  656.    Interior^.DrawView
  657. END;
  658.  
  659. PROCEDURE TANSIView.ClrEol;
  660. BEGIN
  661.    WITH Interior^ DO BEGIN
  662.       MoveChar(TopPtr^[CurLoc.Y]^[CurLoc.X],' ',TextAttr,MaxDim.X - CurLoc.X);
  663.       DrawView
  664.    END
  665. END;
  666.  
  667. PROCEDURE TANSIView.DelLine;
  668. VAR   PPtr : PScreenL;
  669. BEGIN
  670.    WITH Interior^ DO BEGIN
  671.       PPtr := TopPtr^[CurLoc.Y];
  672.       IF CurLoc.Y < MaxDim.Y - 1 THEN
  673.          MOVE(TopPtr^[CurLoc.Y + 1],TopPtr^[CurLoc.Y],(MaxDim.Y - CurLoc.Y) * SIZEOF(PScreenL));
  674.       TopPtr^[MaxDim.Y - 1] := PPtr;
  675.       MoveChar(PPtr^,' ',TextAttr,MaxDim.X);
  676.       DrawView
  677.    END
  678. END;
  679.  
  680. PROCEDURE TANSIView.GotoXY;
  681. BEGIN
  682.    WITH Interior^ DO BEGIN
  683.       CurLoc.X := Max(X - 1,0);
  684.       CurLoc.X := Min(CurLoc.X,MaxDim.X - 1);
  685.  
  686.       CurLoc.Y := Max(Y - 1,0);
  687.       CurLoc.Y := Min(CurLoc.Y,MaxDim.Y - 1);
  688.       SetCursor(CurLoc.X,CurLoc.Y)
  689.    END
  690. END;
  691.  
  692. PROCEDURE TANSIView.HighVideo;
  693. BEGIN
  694.    TextAttr := TextAttr OR $08
  695. END;
  696.  
  697. PROCEDURE TANSIView.InsLine;
  698. VAR   PPtr : PScreenL;
  699. BEGIN
  700.    WITH Interior^ DO BEGIN
  701.       PPtr := TopPtr^[MaxDim.Y - 1];
  702.       IF CurLoc.Y < MaxDim.Y - 1 THEN
  703.          MOVE(TopPtr^[CurLoc.Y],TopPtr^[CurLoc.Y + 1],(MaxDim.Y - CurLoc.Y) * SIZEOF(PScreenL));
  704.       TopPtr^[CurLoc.Y] := PPtr;
  705.       MoveChar(PPtr^,' ',TextAttr,MaxDim.X);
  706.       DrawView
  707.    END
  708. END;
  709.  
  710. PROCEDURE TANSIView.LowVideo;
  711. BEGIN
  712.    TextAttr := TextAttr AND (NOT $08)
  713. END;
  714.  
  715. PROCEDURE TANSIView.TextBackground;
  716. BEGIN
  717.    TextAttr := (Color AND $03) SHL 4 + (TextAttr AND $8F)
  718. END;
  719.  
  720. PROCEDURE TANSIView.TextColor;
  721. BEGIN
  722.    TextAttr := (TextAttr AND $F0) + (Color AND $0F)
  723. END;
  724.  
  725. FUNCTION TANSIView.WhereX;
  726. BEGIN
  727.    WhereX := Interior^.CurLoc.X
  728. END;
  729.  
  730. FUNCTION TANSIView.WhereY;
  731. BEGIN
  732.    WhereY := Interior^.CurLoc.Y
  733. END;
  734.  
  735. {----------------------------------------------------------------------------}
  736.  
  737. PROCEDURE RegisterANSIView;
  738. BEGIN
  739.    RegisterType(RANSIView);
  740.    RegisterType(RInterior);
  741. END;
  742.  
  743. END.